import asyncio
import json
import httpx

key = "sk-Hw7emjtlsiCXWBC52fF9DfBb12Da4c43B3E9Fe4a3e287625"  # 你的key
url = "https://jp.suancaiyv.cfd:3001/v1/chat/completions"  # 请求url

headers = {
    "Authorization": f"Bearer {key}",
    "Content-Type": "application/json"
}

sys_msg = '''
你是一名资深评论分析师，通过读取用户评论，分析该用户是否需要游戏代练陪玩，将评论类型分为一定，极可能，可能，不一定，不是。
你必须遵守以下原则：
1.只需回复评论类型即可，不用回复其他内容。
2.触发以下特殊条件就一定是
比如前面询问的后面还稳价格的
xx到xx多少，
xx标多少，
后面带价类型的就是一定。
3.触发以下条件就是可能
连跪之类的就是可能是
4.触发以下条件就不是
注意分辨是否是同行的信息，如果是同行的的评论就都不是
'''


async def ai(prompt: str):
    data = {
        "model": "glm-4",  # 模型名称
        "request_id": "8827324787590241918",
        "messages": [
            {"role": "system", "content": sys_msg},
            {"role": "user", "content": ":星耀四上王者"},
            {"role": "assistant", "content": "可能"},
            {"role": "user", "content": "抽不到我我要闹了，新赛季八连跪了"},
            {"role": "assistant", "content": "可能"},
            {"role": "user", "content": "来个人帮我苹果v区上王者，多少合适"},
            {"role": "assistant", "content": "一定"},
            {"role": "user",
             "content": "微区ios  钻石求带  听指挥 尽量少送人头  新手  求大佬带飞  只会辅助 全天24小时在线 不睡觉就是干  随叫随到"},
            {"role": "assistant", "content": "极可能"},
            {"role": "user", "content": "我已经从星耀二回到了钻石 没一点脾气[我想静静]"},
            {"role": "assistant", "content": "不一定"},
            {"role": "user", "content": "赛季初星耀五，我打了六十多把排位还是在星耀五[左上]我都被气笑了"},
            {"role": "assistant", "content": "不一定"},
            {"role": "user", "content": "上荣耀差十颗星"},
            {"role": "assistant", "content": "一定"},
            {"role": "user", "content": "星耀一上王者"},
            {"role": "assistant", "content": "一定"},
            {"role": "user", "content": "20星到五十星要多少钱"},
            {"role": "assistant", "content": "一定"},
            {"role": "user", "content": "星耀一到王者"},
            {"role": "assistant", "content": "一定"},
            {"role": "user", "content": "艾琳小国接吗 今天打完，我现在10779上榜11500"},
            {"role": "assistant", "content": "一定"},
            {"role": "user", "content": "排位40星到45指定橘右京多少"},
            {"role": "assistant", "content": "一定"},
            {"role": "user", "content": "50星瑶表现差一千分谁接"},
            {"role": "assistant", "content": "一定"},
            {"role": "user", "content": "34-50"},
            {"role": "assistant", "content": "一定"},
            {"role": "user", "content": "45-50带价来"},
            {"role": "assistant", "content": "一定"},
            {"role": "user", "content": "39到50有接的不"},
            {"role": "assistant", "content": "一定"},
            {"role": "user", "content": "46-50带价来"},
            {"role": "assistant", "content": "一定"},
            {"role": "user", "content": "46到49"},
            {"role": "assistant", "content": "一定"},
            {"role": "user", "content": "没有人要打孙尚香战力，历史15000香香，高考完没事干[比心][比心]"},
            {"role": "assistant", "content": "不是"},
            {"role": "user", "content": "招代打吗"},
            {"role": "assistant", "content": "不是"},
            {"role": "user", "content": "安卓微区先打后付 包排位 巅峰赛"},
            {"role": "assistant", "content": "不是"},
            {"role": "user", "content": "求关注，司马懿免费带上分[比心][比心][互粉][互粉][互粉][互粉][互粉][互粉]"},
            {"role": "assistant", "content": "不是"},
            {"role": "user", "content": "微区钻石星耀来个跟车的 一星四米"},
            {"role": "assistant", "content": "不是"},
            {"role": "user", "content": "接荣耀小国小魔方"},
            {"role": "assistant", "content": "不是"},
            {"role": "user", "content": "需要上分看我，一星一付诚信第一[看]"},
            {"role": "assistant", "content": "不是"},
            {"role": "user", "content": "接荣耀小国小魔方先打后付"},
            {"role": "assistant", "content": "不是"},
            {"role": "user", "content": "巅峰1700-1900指定孙尚香能打的私信我吧"},
            {"role": "assistant", "content": "一定"},
            {"role": "user", "content": "710我就干了700说实话太少了"},
            {"role": "assistant", "content": "不是"},
            {"role": "user", "content": "来一个要上分的 一把一付 高效率上 大家都放心 诚信 靠谱 真实"},
            {"role": "assistant", "content": "不是"},
            {"role": "user", "content": "需要上分的来一个 一把一付 大家都放心 高效率上星 主打诚信靠谱"},
            {"role": "assistant", "content": "不是"},
            {"role": "user", "content": "上分 一把一付 诚信"},
            {"role": "assistant", "content": "不是"},
            {"role": "user", "content": prompt},
        ],
        "temperature": 0.7
    }
    data = json.dumps(data)
    try:
        async with httpx.AsyncClient() as client:
            response = await client.post(url, headers=headers, data=data, timeout=15)
            result = json.loads(response.text)['choices'][0]['message']['content']
            if result in ['一定', '极可能', '可能']:
                return True, result
            else:
                return False, result
    except Exception as e:
        print(e)
        print(response.text)
        return False, ''


async def main():
    result, text = await ai('可以带我吗？我现在58星')
    print(result, text)


if __name__ == '__main__':
    asyncio.run(main())
